﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Input;
using SharedContent;

namespace MiaProject
{
class Cenario
    {
        public const int FLOOR_TERRAIN = 0;
        public const int FLOOR_GRID = 1;
        public const int BRIDGE = 2;
        public List <Model> modelList;
        
        private int currentLevel;
        private static Cenario instance;

        private Cenario()
        {
            modelList = new List<Model>();
            currentLevel = -1;
        }
        public static Cenario getInstance()
        {
            if (instance == null)
                instance = new Cenario();
            return instance;
        }
        public void startLevel()
        {
            currentLevel++;
            
        }
        public void drawGrid(Matrix view, Matrix projection)
        {
            Vector3[] pos = new Vector3[1];
            float x = 0.0f;
            float y = -150.0f;
            float z = 0.0f;
            //int factor = 1260;
            
            pos[0] = new Vector3(x, y, z);
            /*pos[1] = new Vector3(factor, y, z);
            pos[2] = new Vector3(factor * 2, y, z);
            

            pos[3] = new Vector3(x, y, -factor);
            pos[4] = new Vector3(factor, y, -factor);
            pos[5] = new Vector3(factor * 2, y, -factor);

            pos[6] = new Vector3(x, y, -factor * 2);
            pos[7] = new Vector3(factor, y, -factor *2);
            pos[8] = new Vector3(factor * 2, y, -factor *2);
            */

            Matrix world;

            world = Matrix.Identity * Matrix.CreateTranslation(pos[0]);
            this.modelList[Cenario.FLOOR_TERRAIN].Draw(world, view, projection);
            
            int f = 508;
            for (int i = 0; i < 20; i++)
            {
                world = Matrix.Identity * Matrix.CreateTranslation(new Vector3(0, -150, -850-(f*i)));
                this.modelList[Cenario.BRIDGE].Draw(world, view, projection);
            }

            world = Matrix.Identity * Matrix.CreateTranslation(new Vector3(0, -150, -850 - (f * 20)));
            this.modelList[Cenario.FLOOR_TERRAIN].Draw(world, view, projection);
            
            collision(this.modelList[Cenario.FLOOR_TERRAIN], new Vector3(0, 0, -850 - (f * 20)));

            world = Matrix.Identity * Matrix.CreateTranslation(new Vector3(0, -153, -20000));
            this.modelList[Cenario.FLOOR_GRID].Draw(world, view, projection);
            
            collision(this.modelList[Cenario.FLOOR_GRID], new Vector3(0, 0, -20000));

        }//end of method

        public void collision(Model model,Vector3 pos)
        {
            return;
            /*Player p = Player.getInstance();
            
            BoundingSphere c1, c2;
            Vector3 pos_p = p.pos;
            pos_p.Y = 0;
            c1 = new BoundingSphere(pos_p, p.model.Meshes[0].BoundingSphere.Radius * 0.05f);// * 2
            
            c2 = new BoundingSphere(pos, model.Meshes[0].BoundingSphere.Radius);// * 2
            if (!c1.Intersects(c2))
                p.pos.Y = 500;
            else
                p.pos.Y = 0;
             */
        }


    }
}
